package com.tao.Change.Oop;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;

public class ChangeOop {
    boolean loop = true;
    java.util.Scanner Scanner = new Scanner(System.in);
    String key = "";

    //完成零钱通明细
    String one ="----------零钱通明细----------";

    //完成收益入账
    double money = 0;
    Date date = null;
    double balance = 0;
    SimpleDateFormat sdf = null;//用于日期格式化

    //完成消费
    String note = " ";

    //显示菜单
    public void ShowMenu(){
        do{
            System.out.println("\n==========零钱通菜单(oop)==========");
            System.out.println("\t\t1 零钱通明细");
            System.out.println("\t\t2 收益入账");
            System.out.println("\t\t3 消费");
            System.out.println("\t\t4 退出");

            System.out.println("请选择（1-4）");
            key =Scanner.next();
            switch(key){
                case "1":
                    this.detail();
                    break;
                case "2":
                    this.income();
                    break;
                case "3":
                    this.pay();
                    break;
                case "4":
                    this.exit();
                    break;
                default:
                    System.out.println("输入有误");
            }
        }while(loop);
    }

    //零钱明细
    public void detail(){
        System.out.println(one);
    }

    //入账
    public void income(){
        System.out.println("入账金额:");
        money =Scanner.nextDouble();
        if(money<=0){
            System.out.println("入账金额需要大于0");
            return;
        }
        balance += money;
        date = new Date();
        sdf = new SimpleDateFormat("yyyy-mm-dd hh:mm");
        one +="\n收益入账\t+" + money + "\t" +sdf.format(date) + "\t" + "余额：" + balance;
    }

    //消费
    public void pay(){
        System.out.println("消费金额：");
        money =Scanner.nextDouble();
        if(money<=0||money>balance){
            System.out.println("余额不足");
            System.out.println("您的余额还有：" + balance);
            return;
        }
        System.out.println("花费说明");
        note = Scanner.next();
        balance -= money;
        one +="\n" + note + "\t-" + money + "\t" +sdf.format(date) + "\t" + "余额：" + balance;
    }

    //退出
    public void exit(){
        //让用户判断是否真的要退出
        String choice = " ";
        while(true){
            System.out.println("你确定要退出吗？y/n");
            choice = Scanner.next();
            if("y".equals(choice)||"n".equals(choice)){
                break;
            }
        }
        if("y".equals(choice)){
            loop = false;
        }
        return;
    }
}
